#include <iostream>
#include <vector>
using namespace std;

int rob(vector<int> &nums)
{
    int len = nums.size();
    if (len == 1)
    {
        return nums[0];
    }
    if (len == 2)
    {
        return max(nums[0], nums[1]);
    }
    int dp[2];
    dp[0] = nums[0];
    dp[1] = max(nums[0], nums[1]);
    for (int i = 2; i < len; i++)
    {
        dp[i % 2] = max(dp[(i - 1) % 2], dp[(i - 2) % 2] + nums[i]);
    }
    return dp[(len - 1) % 2];
}

int main(){
    vector<int> nums;
    nums.push_back(1);
    nums.push_back(2);
    nums.push_back(3);
    nums.push_back(1);
    cout<<rob(nums);
    return 0;
}